﻿/**
  KCAKCAK   CAKCAKC   AK      CA
 AK        KC     CA  AK    AK
CA         KC     CA  AK  KC
CA         KCAKCAKCA  AKCA
CA         KC     CA  AK  KC
 AK        KC     CA  AK    AK
  KCAKCAK  KC     CA  AK      CA

_________________________________________________________________
 China ataca Kamchatka - copyright 2007(c) Ruben Sainz de la Maza
 
	@class: 	Players
	@vertion: 	0.1
	@date:		28/11/07
				
	@language: 	ActionScript 3.0
	@author:	Ruben Sainz de la Maza
	@usage: 
		_objPlayers = new Players();
		_objPlayers.init();
		//verificar el funcionamiento
		trace("Crear jugador: "+_objPlayers.createPlayer("Ruben", "AZUL"));
		trace("Crear jugador: "+_objPlayers.createPlayer("Ruben", "NEGRO")); 
		
**/

package com.conelmate.cak.players
{
	
	import com.conelmate.util.Trace;
	
	
	public class Players extends Trace implements IPlayer
	{
		public	const 	NEGRO			:String = "NEGRO";
		public	const 	ROJO			:String = "ROJO";
		public	const 	AMARILLO		:String = "AMARILLO";
		public	const 	AZUL			:String = "AZUL";
		public	const 	BLANCO			:String = "BLANCO";
		public	const 	VERDE			:String = "VERDE";

		private var 	_objPlayers		:Object;			//almacena los objetos Players creados
		
		private var		_isFreeze		:Boolean = false;	//true:congela eventos, false:reactiva eventos
		
		private var 	_intPlayers		:uint = 0;			//cantidad de jugadores


//_________________________________________________________________________________ Constructor
		public function Players()
		{
			_isTrace = false;
			mTrace("#Players# constructor");
			
		}
		

//_________________________________________________________________________________ Public Methods

		/**
		 * Inicializa la clase
		 */
		public function init():void
		{
			mTrace("#Players# init");
			
			_objPlayers = new Object();
		}
		

		/**
		 * Destruye las instancias
		 */
		public function destroy():void
		{
			mTrace("#Players# destroy");
		}
		
		
		/**
		 * Congela / descongela los eventos de la clase
		 * @param   freeze 
		 */		
		public function freeze(freeze:Boolean):void
		{
			mTrace("#Players# freeze");
			_isFreeze = freeze;
		}
		

		/**
		 * Crear un nuevo jugador
		 */		
		public function createPlayer(pColor:String, pName:String):Boolean
		{
			if(_objPlayers[pColor]) return false;
			else {
				var objPlayer:Player = new Player(pColor, pName);
				_objPlayers[pColor] = objPlayer;
				
				//verificar:
				mTrace(_objPlayers[pColor].pName);
				mTrace(_objPlayers[pColor].pColor);
				
				_intPlayers++;
				
				return true;
			}
		}
		
		
		/**
		 * Eliminar a un jugador
		 * @param   pName:Color del jugador
		 */		
		public function destroyPlayer(pColor:String):Boolean
		{
			if(_objPlayers[pColor]){
				_objPlayers[pColor].destroy();
				_objPlayers[pColor] = null;
				_intPlayers--;
				return true;
			} else return false;
		}


		/**
		 * devuelve un objeto Player de acuerdo a la posicion que ocupa dentro del objeto Players
		 * @param   pos :posicion requerida
		 */		
		public function getPlayer(pos:uint):Player
		{
			var count:uint = 0;
			for(var i in _objPlayers){
				count++;
				if(pos == count) break;
			}
			return _objPlayers[i];
		}

//_________________________________________________________________________________ Private Methods

//_________________________________________________________________________________ GETTERS
		public function get intPlayers	():Number	{ return _intPlayers; }
		
//_________________________________________________________________________________ SETTERS

	}
}